<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center" v-if="false">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />用户名
                <div class="pull-right">{{ user.loginId||'--' }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="user" />用户姓名
                <div class="pull-right">{{ user.name||'--' }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.mobileNoCache||'--' }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />用户邮箱
                <div class="pull-right">{{ user.email||'--' }}</div>
              </li>
              <li class="list-group-item" v-if="false">
                <svg-icon icon-class="tree" />所属部门
                <div class="pull-right" v-if="user ">{{ user.deptName }} / {{ postGroup }}</div>
              </li>

              <li class="list-group-item">
                <svg-icon icon-class="date" />创建日期
                <div class="pull-right">{{ user.createTime ||'--'}}</div>
              </li>
              <li class="list-group-item clearfix">
                <svg-icon icon-class="peoples" />所属角色
                <div class="pull-right">{{ user.rolesname ||'--'}}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo" lazy>
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd" lazy>
              <resetPwd :user="user" />
            </el-tab-pane>
            <el-tab-pane label="双因子认证" name="security" lazy>
              <security :user="user" />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
    <br>
    <br>
    <br>
    <el-row :gutter="20" style="textAlign:center" v-if="false">
      <el-alert type="warning" center style="width: 70% ;margin:6px auto" v-if="user.roles.length==0||user.roles.includes(-1)">
        <span slot="title" style="fontSize:18px">
          <i class="el-icon-warning" style="fontSize:20px"></i>
          当前用户尚未分配角色,请联系管理员操作
        </span>
      </el-alert>
      <el-alert type="warning" center style="width: 70% ;margin:6px auto" v-if="user.groups.length==0||user.groups.includes(-1)">
        <span slot="title" style="fontSize:18px">
          <i class="el-icon-warning" style="fontSize:20px"></i>
          当前用户尚未分配用户组,请联系管理员操作
        </span>
      </el-alert>
      <el-alert type="warning" center style="width: 70% ;margin:6px auto" v-if="ruoters.length==1">
        <span slot="title" style="fontSize:18px">
          <i class="el-icon-warning" style="fontSize:20px"></i>
          当前用户尚未分配用户组,请联系管理员操作
        </span>
      </el-alert>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import security from "./security";
import { getUserProfile } from "@/api/system/user";

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd, security },
  data() {
    return {
      user: {
        roles: [],
        groups: [],
      },
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
    };
  },
  computed: {
    ruoters() {
      return this.$store.getters.addRoutes;
    },
  },
  created() {
    this.getUser();
  },

  methods: {
    getUser() {
      getUserProfile().then((response) => {
        if (response.data.roles.includes(-1)) response.data.roles = [];
        if (response.data.groups.includes(-1)) response.data.groups = [];
        response.data.rolesname = response.data.roleList
          .map((item) => {
            return item.roleName;
          })
          .join(",");
        response.data.mobileNoCache = response.data.mobileNo;
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    },
  },
};
</script>
